<template>
  <div class="discover">
    <div class="discover-header">
      <div class="discover-header-inner">
        <div class="discover-header-inner-left" :class="{active:active == 0}" @click="goMessage">资讯</div>
        <div class="discover-header-inner-right" :class="{active:active == 1}" @click="goDiscuss">论坛</div>
      </div>
    </div>
    <router-view></router-view>
  </div>
</template>
<script>
import { Swipe, SwipeItem } from 'mint-ui';
import { dateFormat, LoadMore ,cookie} from 'vux'
export default {
  name: 'discover',
  components: { LoadMore },
  data() {
    return {
      active: -1,
    }
  },
  watch:{
    // 监听路由变化，判断头部active的切换
    $route(newVal,oldVal){
      var path = newVal.path.split('/').pop();
      if(path == 'selected'){
        this.active = 0;
      }else if(path == 'discuss'){
        this.active = 1;
      }
    }
  },
  mounted(){
    // 加载进来的时候也判断路由，确定active在资讯还是论坛
    var path = this.$route.path.split('/').pop();
     if(path == 'selected'){
        this.active = 0;
      }else if(path == 'discuss'){
        this.active = 1;
      }
  },
  methods: {
    goDiscuss() {
      this.$router.push({path:'/main/discover/discuss'});
    },
    goMessage() {
      this.$router.push({path:'/main/discover/selected'});
    }
  }
}
</script>
<style lang="scss">
@import '../../scss/variable/base.scss';

.discover {
  margin-bottom: 1.8rem;
  &-header {
    width: 100%;
    height: 1.2rem;

    background: -webkit-linear-gradient(bottom, #2ce9e8, #7dd7ff);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 3;
    &-inner {
      height: 0.76rem;
      width: 5.4rem; // border: 2px solid #fff;
      position: absolute;
      transform: translate(-50%, -50%);
      border-radius: 0.12rem;
      left: 50%;
      top: 50%;
      &-left {
        width: 48%;
        float: left;
        line-height: 0.76rem;
        border-radius: 0.12rem 0 0 0.12rem;
        border-left: 1px solid #fff;
        border-top: 1px solid #fff;
        border-bottom: 1px solid #fff;
        font-size: 0.42rem;
        color: #fff;
      }
      &-right {
        width: 48%;
        float: left;
        line-height: 0.76rem;
        border-radius: 0 0.12rem 0.12rem 0;
        border-right: 1px solid #fff;
        border-top: 1px solid #fff;
        border-bottom: 1px solid #fff;
        color: #fff;
        font-size: 0.42rem;
      }
      .active {
        background: #fff;
        color: $primaryColor;
      }
    }
  }
  &-discussSelected {
    margin-top: 2.1rem;
    font-size: 0.4rem;
    font-weight: bold;
    margin-bottom: 0.4rem;
  }
  &-content {
    width: 100%;
    box-sizing: border-box;
    padding: 0 0.4rem;
    background: #fff;
    padding-bottom: 0.4rem;
    &-item {
      box-sizing: border-box;
      padding-top: 0.4rem;
      width: 100%;
      height: 3.17rem;
      display: flex;
      &-left {
        width: 3.6rem;
        height: 100%;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      &-right {
        width: 5.32rem;
        height: 100%;
        margin-left: 0.27rem;
        text-align: left;
        border-bottom: 1px solid $borderColor;
        position: relative;
        p {
          font-size: 0.4rem; // height: 0.7rem;
          line-height: 0.7rem;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        span {
          line-height: 0.5rem;
          font-size: 0.25rem;
        }
        div {
          position: absolute;
          bottom: 0.2rem;
          left: 0rem;
          font-size: 0.4rem; // margin-top: 0.83rem;
          img {
            width: 0.4rem;
            height: auto;
            vertical-align: -8%;
          }
        }
      }
    }
  }
  &-goTop {
    box-shadow: 0px 1px 12px rgba(0, 0, 0, 0.2);
    position: fixed;
    bottom: 2rem;
    width: 1.5rem;
    height: 1.5rem;
    background: #fff;
    text-align: center;
    line-height: 1.5rem;
    border-radius: 50%;
    right: 0.5rem;
    animation: myfirst 1.5s infinite linear;
    i {
      font-size: 0.8rem;
      color: $primaryColor;
    }
    @-webkit-keyframes myfirst {
      0% {
        right: 0.2rem;
      }
      50% {
        right: 0.5rem;
      }
      100% {
        right: 0.2rem;
      }
    }
  }
}
</style>


